<?php

namespace App\HttpController\Sys\Web;


use App\Common\Web\TempFile;
use App\HttpController\ControllerWeb;

class F_file extends ControllerWeb
{
    public function index()
    {
        $file_name = str_replace('f__', '', $this->reqParam('page'));

        $app_cookie = $this->funcAppCookie();

        $t_file = new TempFile($file_name, $app_cookie);
        $r = $t_file->funcPageContent();
        if ($r->err())
        {
            if ($r->errcode == 404)
            {
                $this->response()->withStatus(404, $r->errmsg);
            }
            else
            {
                $this->funcWriteErrR($r);
            }

            return;
        }

        $content = $r->getData('page_content');


        switch ($t_file->fileType())
        {
            case 'js':
                $this->response()->withHeader('Content-Type', 'text/plain');
                $this->response()->withHeader('Cache-Control', 'max-age=600, public');
                break;

            case 'css':
                $this->response()->withHeader('Content-Type', 'text/css');
                $this->response()->withHeader('Cache-Control', 'max-age=600, public');
                break;
        }


        $this->response()->write($content);

//        $this->commonR()->setData('file_path', $file_path);
//        $this->commonR()->setData('content', $content);
//        $this->funcWriteCommonR();
    }
}